package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.common.persistence.model.MonthbalanceDetail;
import com.stylefeng.guns.modular.system.service.IMonthbalanceDetailService;

/**
 * 月结应收款控制器
 *
 * @author fengshuonan
 * @Date 2018-03-14 19:51:39
 */
@Controller
@RequestMapping("/monthbalanceDetail")
public class MonthbalanceDetailController extends BaseController {

    private String PREFIX = "/system/monthbalanceDetail/";

    @Autowired
    private IMonthbalanceDetailService monthbalanceDetailService;

    /**
     * 跳转到月结应收款首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "monthbalanceDetail.html";
    }

    /**
     * 跳转到打印月结应收款
     */
    @RequestMapping("/monthbalanceDetail_print")
    public String monthbalanceDetailAdd() {
        return PREFIX + "monthbalanceDetail_print.html";
    }

    /**
     * 跳转到修改月结应收款
     */
    @RequestMapping("/monthbalanceDetail_update/{monthbalanceDetailId}")
    public String monthbalanceDetailUpdate(@PathVariable Integer monthbalanceDetailId, Model model) {
        MonthbalanceDetail monthbalanceDetail = monthbalanceDetailService.selectById(monthbalanceDetailId);
        model.addAttribute("item",monthbalanceDetail);
        LogObjectHolder.me().set(monthbalanceDetail);
        return PREFIX + "monthbalanceDetail_edit.html";
    }

    /**
     * 获取月结应收款列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return monthbalanceDetailService.selectList(null);
    }

    /**
     * 新增月结应收款
     */
    @RequestMapping(value = "/print")
    @ResponseBody
    public Object add(MonthbalanceDetail monthbalanceDetail) {
        monthbalanceDetailService.insert(monthbalanceDetail);
        return super.SUCCESS_TIP;
    }

    /**
     * 删除月结应收款
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer monthbalanceDetailId) {
        monthbalanceDetailService.deleteById(monthbalanceDetailId);
        return SUCCESS_TIP;
    }

    /**
     * 修改月结应收款
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(MonthbalanceDetail monthbalanceDetail) {
        monthbalanceDetailService.updateById(monthbalanceDetail);
        return super.SUCCESS_TIP;
    }

    /**
     * 月结应收款详情
     */
    @RequestMapping(value = "/detail/{monthbalanceDetailId}")
    @ResponseBody
    public Object detail(@PathVariable("monthbalanceDetailId") Integer monthbalanceDetailId) {
        return monthbalanceDetailService.selectById(monthbalanceDetailId);
    }
}
